// 判断系统类型 ， 根据系统导出不同的API 函数

// window 上打开 exe 软件，通过软件执行对应的参数
const {promisify} = require("node:util")
const childProcess = require('node:child_process');
const path= require('node:path');

const execFile = promisify(childProcess.execFile);

const binary = path.resolve(__dirname, 'wallpaper.exe');
const wallpaperPath = path.join(__dirname, 'wallhaven-l8228q.jpg');

async function getWallpaper(){
    const arguments = [
        'get',
    ];

    try{
        const {stdout} = await execFile(binary, arguments);
        return stdout.trim();

    }catch(e){

        console.error(e);
    }
}

async function setWallpaper(imagePath,{scale = 'cover'}){
    if (typeof imagePath !== 'string') {
        throw new TypeError('Expected a string');
    }
    console.log("XX", await getWallpaper() , binary)
    const arguments = [
        'set',
        'wallhaven-l8228q.jpg',
    ];

     await execFile(binary, arguments);
}


setWallpaper('wallhaven-l8228q.jpg',{});
